import { token } from '@/utils/token';
import { reqUserInfo } from '@/api/user';
export default {
	// 开启命名空间
	namespaced: true,
	state: {
		// 用户信息
		userInfo: {},
		token: token(),
	},
	mutations: {
		USERLOGIN(state, token) {
			state.token = token;
		},
		GETUSERINFO(state, data) {
			state.userInfo = data;
		},
		//
		REMOVEUSERINFO(state) {
			state.userInfo = {};
		},
		REMOVETOKEN(state) {
			state.token = '';
		},
	},
	actions: {
		async getUserInfo({ commit }) {
			const result = await reqUserInfo();
			if (result.data.code === 200) {
				commit('GETUSERINFO', result.data.data);
			} else {
				console.log(result);
				return Promise.reject(new Error(result.data.code));
			}
		},
	},
	getters: {},
};
